<?php

/**
 * fotos actions.
 *
 * @package    sanziniafilms
 * @subpackage index
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class fotosActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request){
	$this->getResponse()->setTitle("Fotos | Sanzinia Films");
	if($request->getParameter('id')==""){
		$this->treeObject = Doctrine_Core::getTable('Tree')->getTree();
		
	}
	else{
		$this->treeObject = Doctrine_Core::getTable('Tree')->findOneById($request->getParameter('id'))->getNode();
		$roots = $this->treeObject->getChildren();
		$this->children = $roots->getData(); 
		usort($this->children, array('Tree', 'compareChildren'));
		$this->titleCollection = Doctrine_Core::getTable('Tree')->findOneById($request->getParameter('id'))->getTitulo();
	}
  }
  
  public function executeAlbum(sfWebRequest $request){
	$this->getResponse()->setTitle("Fotos | Sanzinia Films");
	if($request->getParameter('id')!=""){
		$this->albumPhotos = Doctrine_Query::create()->select('p.*')->from('Photo p')->where('p.tree_id = ?', $request->getParameter('id'))->orderBy('p.orderId')->execute();
		$this->album = Doctrine_Core::getTable('Tree')->findOneById($request->getParameter('id'));
		$this->getResponse()->setTitle($this->album->getTitulo()." Fotos | Sanzinia Films");
	}
	else{
		$this->redirect('fotos/index');
	}
  }
  
  public function executeFavoritas(sfWebRequest $request){
		$this->albumPhotos = Doctrine_Query::create()->select('p.*')->from('Photo p')->where('p.favorito = ?', 1)->orderBy('p.orderId')->execute();
		$this->album = Doctrine_Core::getTable('Tree')->findOneByTitulo("Favoritas");
		$this->setTemplate('album');
  }
}
